﻿<!DOCTYPE HTML>
<html>
<head>
	<meta charset="utf-8">
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
	<meta http-equiv="Cache-Control" content="no-siteapp" />
	<!--[if lt IE 9]>
	<script type="text/javascript" src="/lib/html5shiv.js"></script>
	<script type="text/javascript" src="/lib/respond.min.js"></script>
	<![endif]-->
	<link rel="stylesheet" type="text/css" href="/h-ui/css/H-ui.min.css" />
	<link rel="stylesheet" type="text/css" href="/h-ui.admin/css/H-ui.admin.css" />
	<link rel="stylesheet" type="text/css" href="/lib/Hui-iconfont/1.0.8/iconfont.css" />
	<link rel="stylesheet" type="text/css" href="/h-ui.admin/skin/default/skin.css" id="skin" />
	<link rel="stylesheet" type="text/css" href="/h-ui.admin/css/style.css" />
	<!--[if IE 6]>
	<script type="text/javascript" src="/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
	<script>DD_belatedPNG.fix('*');</script>
	<![endif]-->
	<link rel="stylesheet" href="/lib/zTree/v3/css/zTreeStyle/zTreeStyle.css" type="text/css">
</head>
<body class="pos-r">
<div class="pos-a" style="width:400px;left:10px;top:0; bottom:0; height:100%; border-right:1px solid #ffffff; background-color:#ffffff; overflow:auto;">
	<ul id="treeDemo" class="ztree"></ul>
	<a class="btn btn-primary radius" href="javascript:;" id="role_assign"><i class="Hui-iconfont">&#xe600;</i> 分配角色</a>
</div>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="/h-ui.admin/js/H-ui.admin.js"></script>
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/lib/zTree/v3/js/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="/lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript">
	var zNodes = '';
	//ajax获取所有的menu
	$.ajax({
		type : 'post',
		url : '/initMenu?rights='+${rights},
		async : false,
		success : function (data) {
			zNodes = data.nodes;
		}
	});
	var setting = {
		view: {
			selectedMulti: false
		},
		check: {
			enable: true
		},
		data: {
			simpleData: {
				enable: true
			}
		},
		callback: {
			beforeCheck: beforeCheck,
			onCheck: onCheck
		}
	};
	var code, log, className = "dark";
	function beforeCheck(treeId, treeNode) {
		className = (className === "dark" ? "":"dark");
		showLog("[ "+getTime()+" beforeCheck ]&nbsp;&nbsp;&nbsp;&nbsp;" + treeNode.name );
		return (treeNode.doCheck !== false);
	}
	function onCheck(e, treeId, treeNode) {
		showLog("[ "+getTime()+" onCheck ]&nbsp;&nbsp;&nbsp;&nbsp;" + treeNode.name );
	}
	function showLog(str) {
		if (!log) log = $("#log");
		log.append("<li class='"+className+"'>"+str+"</li>");
		if(log.children("li").length > 6) {
			log.get(0).removeChild(log.children("li")[0]);
		}
	}
	function getTime() {
		var now= new Date(),
				h=now.getHours(),
				m=now.getMinutes(),
				s=now.getSeconds(),
				ms=now.getMilliseconds();
		return (h+":"+m+":"+s+ " " +ms);
	}

	function checkNode(e) {
		var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
				type = e.data.type,
				nodes = zTree.getSelectedNodes();
		if (type.indexOf("All")<0 && nodes.length == 0) {
			alert("请先选择一个节点");
		}

		if (type == "checkAllTrue") {
			zTree.checkAllNodes(true);
		} else if (type == "checkAllFalse") {
			zTree.checkAllNodes(false);
		} else {
			var callbackFlag = $("#callbackTrigger").attr("checked");
			for (var i=0, l=nodes.length; i<l; i++) {
				if (type == "checkTrue") {
					zTree.checkNode(nodes[i], true, false, callbackFlag);
				} else if (type == "checkFalse") {
					zTree.checkNode(nodes[i], false, false, callbackFlag);
				} else if (type == "toggle") {
					zTree.checkNode(nodes[i], null, false, callbackFlag);
				}else if (type == "checkTruePS") {
					zTree.checkNode(nodes[i], true, true, callbackFlag);
				} else if (type == "checkFalsePS") {
					zTree.checkNode(nodes[i], false, true, callbackFlag);
				} else if (type == "togglePS") {
					zTree.checkNode(nodes[i], null, true, callbackFlag);
				}
			}
		}
	}

	function setAutoTrigger(e) {
		var zTree = $.fn.zTree.getZTreeObj("treeDemo");
		zTree.setting.check.autoCheckTrigger = $("#autoCallbackTrigger").attr("checked");
		$("#autoCheckTriggerValue").html(zTree.setting.check.autoCheckTrigger ? "true" : "false");
	}

	$(document).ready(function(){
		$.fn.zTree.init($("#treeDemo"), setting, zNodes);
		$("#checkTrue").bind("click", {type:"checkTrue"}, checkNode);
		$("#checkFalse").bind("click", {type:"checkFalse"}, checkNode);
		$("#toggle").bind("click", {type:"toggle"}, checkNode);
		$("#checkTruePS").bind("click", {type:"checkTruePS"}, checkNode);
		$("#checkFalsePS").bind("click", {type:"checkFalsePS"}, checkNode);
		$("#togglePS").bind("click", {type:"togglePS"}, checkNode);
		$("#checkAllTrue").bind("click", {type:"checkAllTrue"}, checkNode);
		$("#checkAllFalse").bind("click", {type:"checkAllFalse"}, checkNode);
		$("#autoCallbackTrigger").bind("change", {}, setAutoTrigger);
	});
</script>
<script type="text/javascript">
	$("#role_assign").click(function(){
		var t = $.fn.zTree.getZTreeObj("treeDemo");
		var ID = ${role_id};
		var checkCount = t.getCheckedNodes(true);
		var result = [];
		for(var i=0;i<checkCount.length;i++) {
			result[i] = checkCount[i].id;
		}
		$.ajax({
			type : 'post',
			url : '/admin-role-assign?tm=' + new Date().getTime()+"&rights="+result,
			data : {ID:ID},
			async : false,
			success : function () {
				//还是存在抖动
				window.parent.location.reload();
				var index = parent.layer.getFrameIndex(window.name);
				parent.layer.close(index);
			}
		})
	})
</script>
</body>
</html>